package com.hnkywl.sts.dao.jhgl;

import com.hnkywl.sts.entity.jhgl.Tpwzjh;
import com.hnkywl.sts.service.sys.YgService;
import net.ruixin.orm.hibernate.Page;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-4-3
 * Time: 上午10:00
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TpwzjhDao extends WzjhDao<Tpwzjh> {
    /*todo*/
    public Page<Tpwzjh> findTpwzjhNoZjjh(Long ssgsId, String spzt, int pageNo, int pageSize) {
        Page<Tpwzjh> page = new Page<Tpwzjh>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setAutoCount(true);
        page.setOrder("desc");
        page.setOrderBy("w.dateCreated");
        List<Object> param = new ArrayList<Object>();
        List<String> conditions = new ArrayList<String>();
        if (ssgsId != null) {
            conditions.add(" w.tcbm.id=? ");
            param.add(YgService.getCurrentYgGsId());
        }
        if (StringUtils.isNotEmpty(spzt)) {
            conditions.add(" w.zt=? ");
            param.add(spzt);
        }
        String hql = "select w from Tpwzjh w left join w.tpzjjh z where z.id is null " + (conditions.isEmpty() ? "" : " and " + StringUtils.join(conditions, "and "));
        return find(page, hql, param.toArray());
    }

    public void updateTpwzjhmxhdsl(Map tpwzjhmx) {
        String hql = "update Tpwzjhmx set hdsl=? where id=?";
        Query query = this.getSession().createQuery(hql);
        query.setDouble(0, Double.parseDouble(tpwzjhmx.get("hdsl").toString()));
        query.setLong(1, Long.parseLong(tpwzjhmx.get("id").toString()));
        query.executeUpdate();
    }
}
